setlocal enabledelayedexpansion

@REM The path to the WiX directory
@REM set WiXPath=%~1
set WiXPath=""c:\Program Files\Windows Installer XML v3\bin\""

@REM Setup MSI File
set SETUP_MSI="%~dp0NHTrace.msi"

@REM WixObj File
set WIX_OBJ="%~dp0NHTrace.wixobj"


@REM Delete the previous MSI, if present.
del /F %SETUP_MSI%

@REM Build the registry include
"%VSSDK90Install%\VisualStudioIntegration\Tools\Bin\regpkg.exe" /codebase /wixfile:NHTrace.Registry.wxi "%~dp0Bin\NHTrace.dll"


@REM Compile the wxs file
"!WixPath!candle.exe" -out %WIX_OBJ% "%~dp0NHTrace.wxs"
if "!ERRORLEVEL!"=="0" (
  echo "Candle generated %WIX_OBJ%"
) else (
  echo "Candle returned !ERRORLEVEL!"
  exit /b !ERRORLEVEL!
)

@REM Build the installer
"!WixPath!light.exe" -out %SETUP_MSI% %WIX_OBJ% -ext WixUIExtension.dll -ext WixUtilExtension.dll -cultures:en-us

if "!ERRORLEVEL!"=="0" (
  echo "Light generated %SETUP_MSI%"
) else (
  echo "Light returned !ERRORLEVEL!"
  exit /b !ERRORLEVEL!
)

exit /b !ERRORLEVEL!
